import request from "../../utils/request.js"
export default {
	state:{
		detailData:[],
		skuList:[],
		newCartList:[],
		newCart:[],
		cartId:''
	},
	actions:{
		//获取商品数据
		async getdetailData({commit}){
			let result = await request('/getdetailData')
			commit("DETAIL_LIST",result.data)
		},
		//获取sku列表
		async getSkuList({commit}){
			let skuList = await request('/getskuList')
			commit("SKULIST_LIST",skuList.data)
		},
		getId({commit},id){		
			commit("CART_ID",id)
		},
		newCart(context,data){
			setTimeout(()=>{
				context.commit("NEWCART",data)
			},1000)
		}
	
	},
	mutations:{
		DETAIL_LIST(state,detailData){
			state.detailData=detailData
		},
		SKULIST_LIST(state,skuList){
			state.skuList=skuList
			// console.log(state.skuList)
		},
		NEWCART(state,data){
			state.newCart=data
		},
		CART_ID(state,id){
			state.cartId=id
		}
	},
	getters:{
		detailData(state){
			return state.detailData
		},
		imageList(state){
			return state.skuList.filter(item =>{
				if(this.id === item.id){
					return item.imageList
				}
			}) || []
		},
		skuList(state){
		  return state.skuList
		},
		newCartList(state){
		  return state.newCartList
		},
		newCart(state){
		  return state.newCart
		},
		
	},
}